package math

import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"

type ISHL struct{
	base.NoOperandsInstruction
}

func(self *ISHL)Execute(frame *rtda.Frame){
	stack := frame.OperandStack()
	v2 := stack.PopInt()//v2指移动多少bit
	v1 := stack.PopInt()//要进行位移操作的变量
	s := uint32(v2) &0x1f
	result := v1 << s
	stack.PushInt(result)
}

type ISHR struct{
	base.NoOperandsInstruction
}

func (self *ISHR)Execute(frame *rtda.Frame){
	stack := frame.OperandStack()
	v2 := stack.PopInt()
	v1 := stack.PopInt()
	s := uint32(v2)&0x1f
	result := v1 >> s
	stack.PushInt(result)
}

type IUSHR struct{
	base.NoOperandsInstruction
}

func (self *IUSHR)Execute(frame *rtda.Frame){
	stack := frame.OperandStack()
	v2 := stack.PopInt();
	v1 := stack.PopInt();
	s := uint32(v2)&0x1f
	result := int32(uint32(v1) >> s)
	stack.PushInt(result)
}

type LSHL struct{
	base.NoOperandsInstruction
}

func (self *LSHL)Execute(frame *rtda.Frame){
	stack := frame.OperandStack()
	v2 := stack.PopLong()
	v1 := stack.PopLong()
	s := uint32(v2) &0x3f
	result := v1 << s;
	stack.PushLong(result)
}

type LSHR struct{
	base.NoOperandsInstruction
}

func (self *LSHR)Execute(frame *rtda.Frame){
	stack := frame.OperandStack()
	v2 := stack.PopLong()
	v1 := stack.PopLong()
	s := uint32(v2) &0X3f
	result := int64(uint64(v1) >> s)
	stack.PushLong(result)
}

// Logical shift right long
type LUSHR struct{ base.NoOperandsInstruction }

func (self *LUSHR) Execute(frame *rtda.Frame) {
	stack := frame.OperandStack()
	v2 := stack.PopInt()
	v1 := stack.PopLong()
	s := uint32(v2) & 0x3f
	result := int64(uint64(v1) >> s)
	stack.PushLong(result)
}